#!/bin/sh
#
# Usage:
#
#    mktarball <version>
#
# where <version> is either n.n[.n] or n_n[_n]
#

if [ "x$1" = "x" ] ; then
   echo "Version number is missing"
   exit 1
fi

version=`echo $1 | tr . _`
dotversion=`echo $1 | tr _ .`


PROJROOT=~/sourceforge

RELEASE=releases
ROADMAP=roadmap-${dotversion}

RDM_MAKE="${ROADMAP}/src/Makefile
          ${ROADMAP}/src/gtk2/Makefile
          ${ROADMAP}/src/qt/Makefile
          ${ROADMAP}/src/icons/Makefile
          ${ROADMAP}/src/win32/wince_env/Roadmap.vcw"

RDM_SRC=" ${ROADMAP}/src/app_a02.txt
         ${ROADMAP}/src/usstates.txt
         ${ROADMAP}/src/*.[ch]
         ${ROADMAP}/src/gtk/Makefile
         ${ROADMAP}/src/gtk/*.[ch]
         ${ROADMAP}/src/gtk2/*.[ch]
         ${ROADMAP}/src/qt/*.[ch]
         ${ROADMAP}/src/qt/*.cc
         ${ROADMAP}/src/qt/ipkg/zroad*
         ${ROADMAP}/src/unix/Makefile
         ${ROADMAP}/src/unix/*.[ch]
         ${ROADMAP}/src/win32/*.[ch]
         ${ROADMAP}/src/ipkg/mkipkg
         ${ROADMAP}/src/ipkg/INSTALL
         ${ROADMAP}/src/ipkg/roadmap*"

RDM_CFG="${ROADMAP}/src/preferences
         ${ROADMAP}/src/schema
         ${ROADMAP}/src/session
         ${ROADMAP}/src/sprites
         ${ROADMAP}/src/drivers
         ${ROADMAP}/src/*.png
         ${ROADMAP}/src/roadmap.desktop
         ${ROADMAP}/src/roadmap.menu
         ${ROADMAP}/src/icons/rm_*.xpm
         ${ROADMAP}/src/icons/rm_*.png
         ${ROADMAP}/src/win32/icons/rm_*.bmp"

RDM_SH="${ROADMAP}/src/rdmdownload
        ${ROADMAP}/src/rdmgetall
        ${ROADMAP}/src/rdmgenmaps
        ${ROADMAP}/src/rdmgendcwmaps
        ${ROADMAP}/src/rdmcompare"

RDM_BIN="${ROADMAP}/src/usdir.rdm
         ${ROADMAP}/src/usc06075.rdm
         ${ROADMAP}/src/gtk/gtkroadmap
         ${ROADMAP}/src/gtk/gtkroadgps
         ${ROADMAP}/src/gtk2/gtkroadmap
         ${ROADMAP}/src/gtk2/gtkroadgps
         ${ROADMAP}/src/qt/qtroadmap
         ${ROADMAP}/src/qt/qtroadgps
         ${ROADMAP}/src/buildmap
         ${ROADMAP}/src/buildus
         ${ROADMAP}/src/rdmghost
         ${ROADMAP}/src/rdmfriends
         ${ROADMAP}/src/rdmkismet"

RDM_DOC="${ROADMAP}/AUTHORS
         ${ROADMAP}/BUGS
         ${ROADMAP}/COPYING
         ${ROADMAP}/README
         ${ROADMAP}/src/roadgps.1
         ${ROADMAP}/src/roadmap.1"

RDM_HELP="${ROADMAP}/web/manual.html ${ROADMAP}/web/apt_toc.gif"

RDM_IPK="arm/familiar/roadmap/ipkg/roadmap_${dotversion}_arm.ipk"


cd $PROJROOT

mkdir -p $RELEASE
ln -s roadmap ${ROADMAP}

rm -f roadmap/src/*.rdm
for i in usdir usc06075
do
   cp /usr/local/share/roadmap/$i.rdm roadmap/src
done

echo "Creating tar ball for section doc ..."
rm -f $RELEASE/roadmap_${version}_doc.tar*
cp roadmap/src/ipkg/INSTALL roadmap/INSTALL.familiar
aptconvert -enc ASCII -toc roadmap/web/manual.html roadmap/README
aptconvert -enc ASCII -toc roadmap/web/familiar.html roadmap/src/ipkg/INSTALL
tar cf $RELEASE/roadmap_${version}_doc.tar $RDM_DOC ${ROADMAP}/web ${ROADMAP}/INSTALL.familiar
rm -f roadmap/INSTALL.familiar

echo "Creating tar ball for section src ..."
rm -f $RELEASE/roadmap_${version}_src.tar*
tar cf $RELEASE/roadmap_${version}_src.tar $RDM_MAKE $RDM_SRC $RDM_SH $RDM_CFG $RDM_DOC

echo "Creating tar ball for section i686 ..."
rm -f $RELEASE/roadmap_${version}_i686.tar*
tar cf $RELEASE/roadmap_${version}_i686.tar $RDM_MAKE $RDM_BIN $RDM_SH $RDM_CFG $RDM_DOC $RDM_HELP

echo "Creating tar ball for section armv4l ..."
roadmap/src/ipkg/mkipkg $dotversion
echo "  Done with ipkg"

rm -f $RELEASE/roadmap_${version}_armv4l.tar*
rm -f roadmap/*.ipk
cp $RDM_IPK roadmap
cp roadmap/src/ipkg/INSTALL roadmap
tar cf $RELEASE/roadmap_${version}_armv4l.tar ${ROADMAP}/*.ipk $RDM_DOC ${ROADMAP}/INSTALL
rm -f roadmap/*.ipk roadmap/INSTALL

rm -f roadmap/src/*.rdm 

rm -f ${ROADMAP}


cd $RELEASE

for x in doc src i686 armv4l
do
  echo "Compressing tar ball for section $x ..."
  gzip -9 roadmap_${version}_$x.tar
done

